import axios from "axios";
axios.defaults.withCredentials = true
export default (url = "", data = {}, type = "get") => {
  url = process.env.VUE_APP_URL + url;
  // console.log("fetch--Url:", url);
  // const headers = {
  //   Accept: "application/json",
  //   "Content-Type": "application/json",
  // };
  // console.log(data);
  if (type == "get") {
    return new Promise(async (resolve, reject) => {
      await axios
        .get(url, {
          params: data
        })
        .then((res) => {
          // console.log(res);
          resolve(res);
        })
        .catch((error) => {
          console.log(error);
          reject(error);
        });
    });
  } else {
    console.log(type);
    return new Promise(async (resolve, reject) => {
      axios[type](url, data)
        .then((res) => {
          // console.log(res);
          if (res.status == 200) {
            resolve(res.data);
          } else {
            resolve(res);
          }
        })
        .catch((error) => {
          reject(error);
        });
    });
  }
};
